package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.dao.TaxLoanRecordInfoDao;
import com.irdstudio.efp.rule.service.domain.TaxLoanRecordInfo;
import com.irdstudio.efp.rule.service.facade.TaxLoanRecordInfoService;
import com.irdstudio.efp.rule.service.vo.TaxLoanRecordInfoVO;

/**
 * <p>ServiceImpl: 获贷查询记录信息表				<p>
 * @author ligm
 * @date 2019-05-15
 */
@Service("taxLoanRecordInfoService")
public class TaxLoanRecordInfoServiceImpl implements TaxLoanRecordInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxLoanRecordInfoServiceImpl.class);

	@Autowired
	private TaxLoanRecordInfoDao taxLoanRecordInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertTaxLoanRecordInfo(TaxLoanRecordInfoVO inTaxLoanRecordInfoVo) {
		logger.debug("当前新增数据为:"+ inTaxLoanRecordInfoVo.toString());
		int num = 0;
		try {
			TaxLoanRecordInfo taxLoanRecordInfo = new TaxLoanRecordInfo();
			beanCopy(inTaxLoanRecordInfoVo, taxLoanRecordInfo);
			num = taxLoanRecordInfoDao.insertTaxLoanRecordInfo(taxLoanRecordInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(TaxLoanRecordInfoVO inTaxLoanRecordInfoVo) {
		logger.debug("当前删除数据条件为:"+ inTaxLoanRecordInfoVo);
		int num = 0;
		try {
			TaxLoanRecordInfo taxLoanRecordInfo = new TaxLoanRecordInfo();
			beanCopy(inTaxLoanRecordInfoVo, taxLoanRecordInfo);
			num = taxLoanRecordInfoDao.deleteByPk(taxLoanRecordInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxLoanRecordInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(TaxLoanRecordInfoVO inTaxLoanRecordInfoVo) {
		logger.debug("当前修改数据为:"+ inTaxLoanRecordInfoVo.toString());
		int num = 0;
		try {
			TaxLoanRecordInfo taxLoanRecordInfo = new TaxLoanRecordInfo();
			beanCopy(inTaxLoanRecordInfoVo, taxLoanRecordInfo);
			num = taxLoanRecordInfoDao.updateByPk(taxLoanRecordInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxLoanRecordInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public TaxLoanRecordInfoVO queryByPk(TaxLoanRecordInfoVO inTaxLoanRecordInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxLoanRecordInfoVo);
		try {
			TaxLoanRecordInfo queryTaxLoanRecordInfo = new TaxLoanRecordInfo();
			beanCopy(inTaxLoanRecordInfoVo, queryTaxLoanRecordInfo);
			TaxLoanRecordInfo queryRslTaxLoanRecordInfo = taxLoanRecordInfoDao.queryByPk(queryTaxLoanRecordInfo);
			if (Objects.nonNull(queryRslTaxLoanRecordInfo)) {
				TaxLoanRecordInfoVO outTaxLoanRecordInfoVo = beanCopy(queryRslTaxLoanRecordInfo, new TaxLoanRecordInfoVO());
				logger.debug("当前查询结果为:"+ outTaxLoanRecordInfoVo.toString());
				return outTaxLoanRecordInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxLoanRecordInfoVO> queryAllOwner(TaxLoanRecordInfoVO taxLoanRecordInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<TaxLoanRecordInfoVO> list = null;
		try {
			List<TaxLoanRecordInfo> taxLoanRecordInfos = taxLoanRecordInfoDao.queryAllOwnerByPage(taxLoanRecordInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ taxLoanRecordInfos.size());
			pageSet(taxLoanRecordInfos, taxLoanRecordInfoVo);
			list = (List<TaxLoanRecordInfoVO>) beansCopy(taxLoanRecordInfos, TaxLoanRecordInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxLoanRecordInfoVO> queryAllCurrOrg(TaxLoanRecordInfoVO taxLoanRecordInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<TaxLoanRecordInfo> taxLoanRecordInfos = taxLoanRecordInfoDao.queryAllCurrOrgByPage(taxLoanRecordInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+taxLoanRecordInfos.size());
		List<TaxLoanRecordInfoVO> list = null;
		try {
			pageSet(taxLoanRecordInfos, taxLoanRecordInfoVo);
			list = (List<TaxLoanRecordInfoVO>) beansCopy(taxLoanRecordInfos, TaxLoanRecordInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<TaxLoanRecordInfoVO> queryAllCurrDownOrg(TaxLoanRecordInfoVO taxLoanRecordInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<TaxLoanRecordInfo> taxLoanRecordInfos = taxLoanRecordInfoDao.queryAllCurrDownOrgByPage(taxLoanRecordInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ taxLoanRecordInfos.size());
		List<TaxLoanRecordInfoVO> list = null;
		try {
			pageSet(taxLoanRecordInfos, taxLoanRecordInfoVo);
			list = (List<TaxLoanRecordInfoVO>) beansCopy(taxLoanRecordInfos, TaxLoanRecordInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public List<TaxLoanRecordInfoVO> queryAllByCondition(TaxLoanRecordInfoVO taxLoanRecordInfoVo) {
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<TaxLoanRecordInfo> taxLoanRecordInfos = taxLoanRecordInfoDao.queryAllByCondition(taxLoanRecordInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ taxLoanRecordInfos.size());
		List<TaxLoanRecordInfoVO> list = null;
		try {
			pageSet(taxLoanRecordInfos, taxLoanRecordInfoVo);
			list = (List<TaxLoanRecordInfoVO>) beansCopy(taxLoanRecordInfos, TaxLoanRecordInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<TaxLoanRecordInfoVO> queryAllByLmtApplySeq(TaxLoanRecordInfoVO taxLoanRecordInfoVO) {
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<TaxLoanRecordInfo> taxLoanRecordInfos = taxLoanRecordInfoDao.queryAllByLmtApplySeq(taxLoanRecordInfoVO);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ taxLoanRecordInfos.size());
		List<TaxLoanRecordInfoVO> list = null;
		try {
			pageSet(taxLoanRecordInfos, taxLoanRecordInfoVO);
			list = (List<TaxLoanRecordInfoVO>) beansCopy(taxLoanRecordInfos, TaxLoanRecordInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
}
